cmake_minimum_required (VERSION 3.26)
project (HDF5_JAVA_JSRC Java)

set (CMAKE_VERBOSE_MAKEFILE 1)

set_directory_properties(PROPERTIES INCLUDE_DIRECTORIES "${HDF5_JAVA_JSRC_BINARY_DIR}")

file (GLOB HDF5_JAVA_JSRC_SOURCES
    LIST_DIRECTORIES false
    ${HDF5_JAVA_JSRC_BINARY_DIR}/org/hdfgroup/javahdf5/*.java
)

file (WRITE ${PROJECT_BINARY_DIR}/Manifest.txt
"Enable-Native-Access: ALL-UNNAMED
"
)

set (CMAKE_JAVA_INCLUDE_PATH "${HDF5_JAVA_LOGGING_JAR}")

# Set version suffix for snapshots vs releases
if (HDF5_ENABLE_MAVEN_DEPLOY AND HDF5_MAVEN_SNAPSHOT)
  set (HDF5_JAVAHDF5_VERSION_SUFFIX "-SNAPSHOT")
else ()
  set (HDF5_JAVAHDF5_VERSION_SUFFIX "")
endif ()

add_jar (${HDF5_JAVA_JSRC_LIB_TARGET} OUTPUT_NAME "${HDF5_JAVA_JSRC_LIB_TARGET}-${HDF5_PACKAGE_VERSION}${HDF5_JAVAHDF5_VERSION_SUFFIX}" MANIFEST ${PROJECT_BINARY_DIR}/Manifest.txt ${HDF5_JAVA_JSRC_SOURCES})
install_jar (${HDF5_JAVA_JSRC_LIB_TARGET} LIBRARY DESTINATION ${HDF5_INSTALL_JAR_DIR} COMPONENT libraries)
get_target_property (${HDF5_JAVA_JSRC_LIB_TARGET}_JAR_FILE ${HDF5_JAVA_JSRC_LIB_TARGET} JAR_FILE)
SET_GLOBAL_VARIABLE (HDF5_JAVA_JARS_TO_EXPORT "${HDF5_JAVA_JARS_TO_EXPORT};${${HDF5_JAVA_JSRC_LIB_TARGET}_JAR_FILE}")
SET_GLOBAL_VARIABLE (HDF5_JAVAHDF5_JARS ${${HDF5_JAVA_JSRC_LIB_TARGET}_JAR_FILE})
SET_GLOBAL_VARIABLE (HDF5_JAVA_JARS "${HDF5_JAVA_JARS};${${HDF5_JAVA_JSRC_LIB_TARGET}_JAR_FILE}")

set_target_properties (${HDF5_JAVA_JSRC_LIB_TARGET} PROPERTIES FOLDER libraries/java)
if (HDF5_ENABLE_FORMATTERS)
  clang_format (HDF5_JAVA_SRC_FORMAT ${HDF5_JAVA_JSRC_SOURCES})
endif ()

set (CMAKE_JAVA_INCLUDE_PATH "")

